<!DOCTYPE html>
<html lang="en" >
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/BlogAdmin/layui/css/layui.css" media="all">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend style="text-align: center">iArchie博客</legend>
</fieldset>
<div style="padding: 20px; background-color: #F2F2F2;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">评论管理信息</div>
               
                            <div class="layui-card-body">
                                <div class="layui-form-item">

                            <button id="addMemory" class="layui-btn layui-btn-warm layui-btn-radius" lay-event="edit">点击添加</button>

                        </div>
                        <table id="demo" lay-filter="test"></table>
                    </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit1">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">新增一条时间线</a>
</script>
<script src="/BlogAdmin/layui/layui.js"></script>
<script src="/LayuiBlog/js/jquery-min.js"></script>
<script type="text/javascript" src="/BlogAdmin/js/wangEditor.min.js"></script>
<script>
</script>
<script>
    layui.use('table', function () {
        var table = layui.table;

        //第一个实例
        table.render({
            elem: '#demo'
            , height: 600
            , url: '/admin/getMemmoryListMang'
            , page: true
            ,parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": 0, //解析接口状态
                    "msg": "", //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": res.data //解析数据列表
                };
            }
            , request: {
                pageName: 'pageNum', //页码的参数名称，默认：page
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , cols: [
                        [
                {type: 'checkbox', fixed: 'left'}
                , {field: 'memoryid', title: 'ID', width: 90, sort: true}
                , {field: 'memoryContent', title: '评论内容', width: 430, sort: true}
                , {field: 'createTime', title: '创建时间', width: 150}
                , {field: 'updateTime', title: '更新时间', width: 150}
                , {field: 'year', title: '年份', width: 150}
                , {
                    fixed: 'right',
                    title: '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;操作',
                    toolbar: '#barDemo',
                    width: 230                }
                    ]
                ]
                ,done: function () {
                layer.msg("获得时间线成功！", {icon: 6});
            }
        });
        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            //console.log(obj)
            if (obj.event === 'del') {
                layer.confirm('真的删除ID为：'+data.memoryid+"的评论吗？", function (index) {
                    $.ajax({
                        type: 'post',
                        url: "/admin/deleteMemoryByMemoryId",
                        // contentType: "application/x-www-form-urlencoded",
                        dataType: "json",
                        data:{
                            memoryId:data.memoryid
                        },
                        success: function (res) {
                            if (res.result == 1) {
                                layer.msg("删除时间线成功！", {icon: 6});
                            } else {
                                layer.msg("删除时间线失败！", {icon: 5});
                            }
                        },
                        error: function () {
                            layer.msg("删除时间线失败！", {icon: 5});
                        }
                    })
                    obj.del();
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                layer.open({
                    type: 2,
                    area: ['65%', '500px'],
                    title: '编辑时间线',
                    skin: 'layui-layer-rim', //加上边框
                    // btn: ['保存', '取消'],
                    btnAlign: 'c',
                    top: 100,
                    content: ['/admin/layer_model6', 'no'],
                    // content:$("#popUpdateTest") //引用的弹出层的页面层的方式加载修改界面表单
                    success: function (layero, index) {
                        var body = layui.layer.getChildFrame('body', index);
                        body.find("p").val(data.memoryContent);
                    },
                });
            } else if (obj.event === 'edit1') {
                layer.open({
                    type: 2,
                    area: ['65%', '500px'],
                    title: '编辑时间线',
                    skin: 'layui-layer-rim', //加上边框
                    // btn: ['保存', '取消'],
                    btnAlign: 'c',
                    top: 100,
                    content: ['/admin/layer_model6', 'no'],
                    // content:$("#popUpdateTest") //引用的弹出层的页面层的方式加载修改界面表单
                    success: function (layero, index) {
                        var body = layui.layer.getChildFrame('body', index);
                        body.find("p").val(data.memoryContent);
                    },
                });
            }
        });
    });

</script>
</body>
</html>